<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: czq
  Date: 2018/5/16
  Time: 11:57
  To change this template use File | Settings | File Templates.
--%>
<%@page pageEncoding="UTF-8" language="java" %>
<%@ include file="/commons/global.jsp"%>
<html>
<head>
    <title>修改专业</title>
    <script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/respond.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/css/style.css" />
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
</head>
<body>
    <article class="cl pd-20">
        <form  method="post" action="<%=request.getContextPath()%>/manage/major/edit" id="majorForm" class="form form-horizontal" >
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>专业编码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="${major.code}" placeholder="" id="code" name="code" readonly>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>专业名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="${major.name}" placeholder="" id="name" name="name">
                    <input type="text" class="input-text" value="${major.id}" placeholder="" id="id" name="id" hidden>
                    <input name="code2" class="input-text" id="name2" value= "专业名称已经存在" readonly style="color:#F00;" hidden />
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>学年：</label>
                <div class="formControls col-xs-8 col-sm-9"><span class="select-box" style="width:250px;">
                    <select class="select" name="year" size="1">
                        <option value="4年" ${major.year == "4年"?'selected="selected"':''}>4年</option>
                        <option value="5年" ${major.year == "5年"?'selected="selected"':''}>5年</option>
                    </select>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属院系：</label>
                <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:250px;">
				<select class="select" name="departId" size="1">
                    <c:forEach var="depart" items="${list}">
					`<option value="${depart.id}" ${depart.id == major.departId?'selected="selected"':''}>${depart.name}</option>
                    </c:forEach>
				</select>
				</span> </div>
            </div>
            <div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-6">
					<button id="majorAdd" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
					<button id="cancel" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
				</div>
			</div>
        </form>
    </article>
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery/1.9.1/jquery.min.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/layer/2.4/layer.js"></script> 
<%-- 	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/icheck/jquery.icheck.min.js"></script>  --%>
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/h-ui/js/H-ui.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/h-ui.admin/js/H-ui.admin.page.js"></script> 
	<script type="text/javascript">
		$("#cancel").click(function(){
			parent.layer.close(parent.index);
		});
		$("#name").blur(function(){
		    var name = $(this).val();
		     //用ajax去数据库匹配，
		    $.ajax({
		        url:"<%=request.getContextPath()%>/manage/major/validate",
		        async : false,
				type : "post",
				dataType : "json",
				data : {
				    "name" : name
				},
				success : function(data) {
                    if (data.msg != "") {
                        $("#name2").show();
                        $("#name").val("");
                    } else {
                        $("#name2").css('display','none');
                    }
				}
		    });    
		})
		
		function majorAdd(){
			var data = $("#majorForm").serialize();
			$.ajax({
				url: $("#majorForm").attr("action"),
				data: data,
				type: "post",
				dataType: "json",
				success: function(result){
					if(result.success){
						top.layer.open({
							icon: 1,
							content: '保存成功！',
							time: 1500
						});
						$(window.parent.document).find("#pageForm").submit();
						parent.layer.close(parent.index);
					}else{
						top.layer.open({
							icon: 2,
							content: '保存失败！',
							time: 1500
						});
					}
				}
			});
		}
		$(function(){
			
			/* 校验 */
			var majorForm;
			
			$("#majorAdd").click(function(){
				if(!majorForm.form()){
					return false;
				}else{
					majorAdd();
				}
			});
			
			majorForm = $("#majorForm").validate({
				"rules":{
					"year":{
						"required":true
					},
					"name":{
						"required":true
					},
				},
				"messages":{
					"year":{
						"required":"学年不能为空！"
					},
					"name":{
						"required":"专业名称不能为空！"
					},
				}
			});
		});
	</script>
</body>
</html>
